package com.vip.oauth2.config;

import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 服务初始化监听的实现
 * 用于实现获取服务IP端口等配置信息
 *
 * @author Rong.Jia
 * @date 2019/02/19 15:24:22
 */
@Component
public class ServerInitListenerImpl implements ApplicationListener<WebServerInitializedEvent> {

    private int serverPort;

    public String getUrl() {
        return "http://127.0.0.1:" + this.serverPort;
    }

    public int getPort() {
        return this.serverPort;
    }

    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {
        this.serverPort = event.getWebServer().getPort();
    }

}
